<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <title>注册教练|私教预约系统</title>
    <link href="../bootstrap-3.3.7-dist/css/bootstrap.min.css"  rel="stylesheet"  type="text/css" >
</head>

<body>
<h1 class="col-sm-offset-5">注册 <span class="label label-default">教练</span></h1>
<form class="form-horizontal">
    <div class="form-group">

    </div>
    <div class="form-group">

    </div>
    <div class="form-group">
        <label for="inputTrainName" class="col-sm-2 control-label">教练姓名</label>
        <div class="col-sm-3">
            <input type="text" class="form-control" id="inputTrainName" placeholder="必填，姓名">
        </div>
    </div>
    <div class="form-group">
        <label for="inputAge" class="col-sm-2 control-label">年龄</label>
        <div class="col-sm-1">
            <input type="text" class="form-control" id="inputAge" placeholder="年龄">
        </div>
    </div>
    <div class="form-group">
        <label for="inputSex" class="col-sm-2 control-label">性别</label>
        <div class="col-sm-1">
            <select class = "select form-control" id = "inputSex"  title="请选择">
                <option value="1">男</option>
                <option value="2">女</option>
            </select>
        </div>
    </div>

    <div class="form-group">
        <label for="onJobDate" class="col-sm-2 control-label">入职日期</label>
        <div class="col-sm-2">
            <input type="date" name="u_bir" class="form-control" height="100px" id="onJobDate" value="2020-01-01"/>
        </div>
    </div>

    <div class="form-group">
        <label for="inputExperience" class="col-sm-2 control-label">教练经验</label>
        <div class="col-sm-2">
            <input type="text" class="form-control" id="inputExperience" placeholder="以年为单位">
        </div>
    </div>

    <div class="form-group">
        <label for="inputPhonenumber" class="col-sm-2 control-label">电话号码</label>
        <div class="col-sm-4">
            <input type="text" class="form-control" id="inputPhoneNumber" placeholder="必填，用电话号码登录">
        </div>
    </div>

    <div class="form-group">
        <label for="inputPassword" class="col-sm-2 control-label">帐号密码</label>
        <div class="col-sm-4">
            <input type="text" class="form-control" id="inputPassword" placeholder="必填">
        </div>
    </div>

    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <input id="signup" type="submit" class="button" value="注册">
        </div>
    </div>
</form>
</body>
<script src="../js/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<script type="text/javascript">
    jQuery(document).ready(function () {
        jQuery("#signup").click(function () {
            let js = getInfo();
            let notNull = check(js);

            jQuery.post("/trainerSignUpRepeatePhoneCheck", js, function (rst) {
                if ("OK" !== rst) {
                    alert(rst);
                }
            })
            if (notNull) {
                jQuery.post("/trainer_signUp", js, function (rst) {
                    if (rst === "注册成功"){
                        alert("注册成功");
                        window.location.reload();
                    } else
                        alert("注册失败");
                })
            }
        })
    })


    function getInfo() {
        let name = jQuery("#inputTrainName").val();
        let age = jQuery("#inputAge").val();
        let options = $("#inputSex option:selected");
        let sex = options.text();
        let onJobDate = jQuery("#onJobDate").val();
        let experience = jQuery("#inputExperience").val();
        let phoneNumber = jQuery("#inputPhoneNumber").val();
        let password = jQuery("#inputPassword").val();

        return {"trainerName": name, "trainerAge": age, "trainerSex": sex, "trainerOnJobTime": onJobDate,
        "trainerExperience": experience, "trainerPhone": phoneNumber, "trainerPassword": password};
    }

    function check(js) {
        let strName = js.trainerName.replace(/(^\s*)|(\s*$)/g,'');
        let strPhone = js.trainerPhone.replace(/(^\s*)|(\s*$)/g,'');
        let strPwd = js.trainerPassword.replace(/(^\s*)|(\s*$)/g,'');
        if(strName==='' || strName===undefined){
            alert("教练姓名不可为空")
        }
        else if(strPhone ==='' || strPhone===undefined){
            alert("手机号码不可为空")
        }
        else if(strPwd ==='' || strPwd===undefined){
            alert("账户密码不可为空")
        }else {
            return true
        }
    }
</script>

</html>
